package cn.edu.gzhu.workOrderManagement.service.impl;

import cn.edu.gzhu.workOrderManagement.properties.SensitiveWordsProperties;
import com.github.houbb.sensitive.word.api.IWordDeny;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
@Service
public class SensitiveWordServiceImpl implements IWordDeny {

    @Autowired
    SensitiveWordsProperties sensitiveWordsProperties;
    /**
     * @return
     */
    @Override
    public List<String> deny() {
        List<String> sensitiveWords = new ArrayList<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(sensitiveWordsProperties.getSensitiveWordsFilePath()))) {
            String line;
            while ((line = reader.readLine()) != null) {
                String[] words = line.split(","); // 按逗号分割
                for (String word : words) {
                    sensitiveWords.add(word.trim()); // 去除空格并添加到列表
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sensitiveWords;
    }
}
